package org.zju.demo.controller;

import org.springframework.web.bind.annotation.*;
import org.zju.demo.model.Order;
import org.zju.demo.model.Product;
import org.zju.demo.model.User;
import org.zju.demo.service.impl.OrderInfoImpl;
import org.zju.demo.service.impl.ProductInfoImpl;
import org.zju.demo.service.impl.UserImpl;
import org.zju.demo.service.intf.OrderInfoIntf;
import org.zju.demo.service.intf.ProductInfoIntf;
import org.zju.demo.service.intf.UserIntf;


/**
 * Created by ZJDX on 2015/8/28.
 */
@RestController
public class AjaxAPIController {
//    @RequestMapping(value = "/add/Product", method = RequestMethod.POST)
//    public ModelAndView addProduct(HttpServletRequest request) {
//
//    }
    @RequestMapping(value = "/api/product", method = RequestMethod.GET)
    public Product getProduct(@RequestParam(value = "productId") Integer productId) {
        ProductInfoIntf productInfoIntf = new ProductInfoImpl();
        Product product = productInfoIntf.findByProductId(productId);
        return product;
    }
    @RequestMapping(value = "/api/user", method = RequestMethod.GET)
    public User getUser(@RequestParam(value = "userId") Integer userId) {
        UserIntf userService = new UserImpl();
        User user = userService.findByUserId(userId);
        return user;
    }
    @RequestMapping(value = "/api/order", method = RequestMethod.GET)
    public Order getOrder(@RequestParam(value = "orderId") Integer orderId) {
        OrderInfoIntf orderService = new OrderInfoImpl();
        Order order = orderService.findById(orderId);
        return order;
    }
}
